package com.ddone.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddone.model.auth.SysOperLog;
import com.ddone.model.vo.Result;
import com.ddone.model.vo.SysOperLogQueryVo;
import com.ddone.service.SysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author ddone
 * @date 2024/4/2-13:14
 */
@Api(tags = {"操作日志API"})
@RestController
@RequestMapping("sys-oper-log")
public class SysOperLogController {
    @Resource
    private SysOperLogService sysOperLogService;

    @PreAuthorize("hasAnyAuthority('bnt.sysOperLog.list')")
    @ApiOperation(value = "获取分页列表")
    @GetMapping("/{page}/{size}")
    public Result<Object> page(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "size", value = "每页记录数", required = true)
            @PathVariable Long size,

            @ApiParam(name = "sysOperLogVo", value = "查询对象", required = false)
                    SysOperLogQueryVo sysOperLogQueryVo) {
        Page<SysOperLog> pageParam = new Page<>(page, size);
        IPage<SysOperLog> pageModel = sysOperLogService.findPage(pageParam, sysOperLogQueryVo);
        return Result.ok(pageModel);
    }


    @PreAuthorize("hasAnyAuthority('bnt.sysOperLog.list')")
    @ApiOperation(value = "获取详情")
    @GetMapping("/{id}")
    public Result<Object> get(@PathVariable Long id) {
        SysOperLog sysOperLog = sysOperLogService.getById(id);
        return Result.ok(sysOperLog);
    }


}
